package 力扣日常刷题.木23一月.第12天312;

/**
 * @author 帅小伙
 * @date 2022/3/12
 * @description
 */
public class Demo47整数反转 {

    public int reverse(int x) {
        int res = 0;
        while(x != 0) {
            if(res < Integer.MIN_VALUE/10 || res > Integer.MAX_VALUE/10) {
                return 0;
            }
            int digit = x % 10;
            x/=10;
            res = res * 10 + digit;
        }
        return res;
    }

}
